//在数据库中验证用户的信息
const user = {
  //查询手机号
  queryUserTel(option) {
    return 'select * from user where tel = ' + option.userTel + ''
  },
  //查询密码
  queryUserPwd(option) {
    return (
      'select * from vm_user where (tel=' +
      option.userAccount +
      ') and pwd = ' +
      option.userPwd +
      ''
    )
  },
  queryUserInfo(option) {
    return (
      'select uid,user_account as userAccount,user_pwd as userPassword,name,nick_name as nickName,age,sex,phone,hobby,avatar,create_time as createTime,token from vm_user where user_account=' +
      option.userAccount
    )
  },
  insertNewUser(data) {
    const userAccount = data.userAccount
    const userPassword = data.userPassword

    let userTel = option.userTel
    let userPwd = option.userPwd || '669988'

    //引入token包
    let jwt = require('jsonwebtoken')
    //用户信息
    let payload = { account: userAccount }
    //口令
    let secret = 'vmall'
    //生成token
    let token = jwt.sign(payload, secret)

    const sql =
      'INSERT INTO vm_user (user_account, user_pwd, phone,token) VALUES (' +
      userAccount +
      ', ' +
      userPassword +
      ', ' +
      userAccount +
      ', ' +
      token +
      ')'
    console.log('sql :>> ', sql)
    return sql
  },
  updateUserPassword(option) {
    return (
      'UPDATE vm_user SET user_pwd = ' +
      option.userPassword +
      ' WHERE user_account = ' +
      option.userAccount
    )
  },
}

exports = module.exports = user
